package com.edu.buservice.facade.config;

import com.edu.buservice.facade.TenantInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-17 11:49
 **/

@Configuration
@AutoConfigureAfter
@Slf4j
@Order(Ordered.HIGHEST_PRECEDENCE)
public class TenantAutoConfiguration implements WebMvcConfigurer {

	@Bean
	@ConditionalOnMissingBean
	public TenantInterceptor tenantInterceptor() {
		log.info("tenantInterceptor init");
		return new TenantInterceptor();
	}

	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		log.info("addInterceptors init");
		registry.addInterceptor(tenantInterceptor()).addPathPatterns("/**");
	}
}
